package slash.game;

import java.util.HashMap;
import java.util.Map;

/**
 * Contains all the elements inside the game.
 */
public class Board {
	private Map<Integer, Entity> allEntities = new HashMap<Integer, Entity>();
	private Cell[][] cells;
	private int height;
	private int width;

	public int getHeight() {
		return height;
	}

	public int getWidth() {
		return width;
	}

	/**
	 * Constructs a new Board with the given dimensions. All Cells in the board
	 * are initialized to new instances of Cells
	 * 
	 * @param width
	 *            The width of the new board.
	 * @param height
	 *            The height of the new board.
	 */
	public Board(int width, int height) {
		this.width = width;
		this.height = height;
		cells = new Cell[width][height];
		for (int x = 0; x < width; x++) {
			for (int y = 0; y < height; y++) {
				cells[x][y] = new Cell(this, x, y);
			}
		}
	}

	/**
	 * Returns the Cell at the given coordinates.
	 */
	public Cell getCell(int x, int y) {
		return cells[x][y];
	}

	/**
	 * Returns the entity with the specified id or null if it isnt found.
	 * 
	 * @param id
	 *            The unique ID of the entity to look up
	 * @return The Entity with the matching ID or null if there is no match.
	 */
	public Entity getEntity(int id) {
		return allEntities.get(id);
	}

	/**
	 * Adds a new Entity into the board.
	 */
	public void addEntity(Entity entity, int x, int y) {
		allEntities.put(entity.getId(), entity);

	}
}
